home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / src / bitprims.h < prev    next >
C/C++ Source or Header  |  1994-10-21  |  4KB  |  126 lines

  1. #ifndef _BS_PRIMS
  2. #define _BS_PRIMS
  3.  
  4. /* For now, use unsigned short for compatibility with old libg++ code.
  5.    Later, change to unsigned long as the default. */
  6. typedef unsigned long _BS_word;
  7.  
  8. #define _BS_CHAR_BIT 8
  9. #define _BS_BITS_PER_WORD (_BS_CHAR_BIT*sizeof(_BS_word))
  10. #define _BS_WORDS_NEEDED(NBITS) ((NBITS+_BS_BITS_PER_WORD-1)/_BS_BITS_PER_WORD)
  11.  
  12. /* For now, we number the bits in a _BS_word in little-endian order.
  13.    Later, might use machine order. */
  14. #ifdef CHILL_LIB
  15. #ifndef BITS_BIG_ENDIAN
  16. #include "config.h"
  17. #endif
  18. #define _BS_BIGENDIAN BITS_BIG_ENDIAN
  19. #else
  20. #define _BS_BIGENDIAN 0
  21. #endif
  22.  
  23. /* By "left" we mean where bit number 0 is.
  24.    Hence, so left shift is << if we're numbering the bits in big-endian oder,
  25.    and >> if we're numbering the bits in little-endian order.
  26.    Currently, we always use little-endian order.
  27.    Later, we might use machine-endian order. */
  28. #if _BS_BIGENDIAN
  29. #define _BS_LEFT <<
  30. #define _BS_RIGHT >>
  31. #else
  32. #define _BS_LEFT >>
  33. #define _BS_RIGHT <<
  34. #endif
  35.  
  36. #if _BS_BIGENDIAN
  37. #define _BS_BITMASK(BITNO) (1 << (_BS_BITS_PER_WORD - 1 - (BITNO)))
  38. #else
  39. #define _BS_BITMASK(BITNO) (1 << (BITNO))
  40. #endif
  41.  
  42. /* Given a PTR which may not be aligned on a _BS_word boundary,
  43.    set NEW_PTR to point to (the beginning of) the corresponding _BS_word.
  44.    Adjust the bit-offset OFFSET to compensate for the difference. */
  45. #define _BS_ADJUST_ALIGNED(NEW_PTR, PTR, OFFSET) \
  46.   ( (NEW_PTR) = (_BS_word*)(((char*)(PTR)-(char*)0) & ~(sizeof(_BS_word)-1)), \
  47.     (OFFSET) += (char*)(PTR) - (char*)(NEW_PTR) )
  48.  
  49. /* Given a bit point (PTR, OFFSET) normalize it so that
  50.    OFFSET < _BS_BITS_PER_WORD. */
  51. #define _BS_NORMALIZE(PTR, OFFSET) \
  52. { _BS_size_t __tmp_ind = _BS_INDEX (OFFSET); \
  53.   (PTR) += __tmp_ind; \
  54.   (OFFSET) -= __tmp_ind * _BS_BITS_PER_WORD; }
  55.  
  56. #define _BS_INDEX(I) ((unsigned)(I) / _BS_BITS_PER_WORD)
  57. #define _BS_POS(I) ((I) & (_BS_BITS_PER_WORD -1 ))
  58.  
  59. #ifndef _BS_size_t
  60. #ifdef __GNUC__
  61. #define _BS_size_t __SIZE_TYPE__
  62. #else
  63. #define _BS_size_t unsigned long
  64. #endif
  65. #endif
  66.  
  67. #ifndef __P
  68. #ifdef __STDC__
  69. #define __P(paramlist) paramlist
  70. #else
  71. #define __P(paramlist) ()
  72. #endif
  73. #endif /*!__P*/
  74. #if !defined(__STDC__) && !defined(const)
  75. #define const
  76. #endif
  77. #if !defined(__STDC__) && !defined(void)
  78. #define void int
  79. #endif
  80.  
  81. /* The 16 2-operand raster-ops:
  82.    These match the correspodning GX codes in X11. */
  83. enum _BS_alu {
  84.   _BS_alu_clear        =  0 /* 0 */,
  85.   _BS_alu_and          =  1 /* src & dst */,
  86.   _BS_alu_andReverse   =  2 /* src & ~dst */,
  87.   _BS_alu_copy         =  3 /* src */,
  88.   _BS_alu_andInverted  =  4 /* ~src & dst */,
  89.   _BS_alu_noop         =  5 /* dst */,
  90.   _BS_alu_xor          =  6 /* src ^ dst */,
  91.   _BS_alu_or           =  7 /* src | dst */,
  92.   _BS_alu_nor          =  8 /* ~src & ~dst */,
  93.   _BS_alu_equiv        =  9 /* ~(src ^ dst) */,
  94.   _BS_alu_invert       = 10 /* ~dst */,
  95.   _BS_alu_orReverse    = 11 /* src | ~dst */,
  96.   _BS_alu_copyInverted = 12 /* ~src */,
  97.   _BS_alu_orInverted   = 13 /* ~src | dst */,
  98.   _BS_alu_nand         = 14 /* ~src | d~st */,
  99.   _BS_alu_set          = 15 /* ~src | dst */
  100. };
  101. #define _BS
  102. #define _BS
  103.  
  104. #ifdef __cplusplus
  105. extern "C" {
  106. #endif
  107.  
  108. extern void _BS_and __P((_BS_word*,int, const _BS_word*, int, _BS_size_t));
  109. extern void _BS_blt __P((enum _BS_alu,
  110.                  _BS_word*,int, const _BS_word*,int, _BS_size_t));
  111. extern void _BS_copy __P((_BS_word*,int, const _BS_word*,int, _BS_size_t));
  112. #define _BS_copy_0(DS, SS, LENGTH) _BS_copy(DS, 0, SS, 0, LENGTH)
  113. extern int _BS_count __P((const _BS_word*, int, _BS_size_t));
  114. extern int _BS_any __P((const _BS_word*, int, _BS_size_t));
  115. extern void _BS_clear __P((_BS_word*, int, _BS_size_t));
  116. extern void _BS_set __P((_BS_word*, int, _BS_size_t));
  117. extern void _BS_invert __P((_BS_word*, int, _BS_size_t));
  118. int _BS_lcompare_0 __P((_BS_word*, _BS_size_t, _BS_word*, _BS_size_t));
  119. extern void _BS_xor __P((_BS_word*,int, const _BS_word*,int, _BS_size_t));
  120.  
  121. #ifdef __cplusplus
  122. }
  123. #endif
  124.  
  125. #endif /* !_BS_PRIMS */
  126.